package com.example.androidshixi;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;

public class ProductDetailActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_product_detail);

        ImageView productImageView = findViewById(R.id.product_detail_image_view);
        TextView productNameTextView = findViewById(R.id.product_detail_name_text_view);
        TextView productDescriptionTextView = findViewById(R.id.product_detail_description_text_view);
        TextView productPriceTextView = findViewById(R.id.product_detail_price_text_view);
        Button addToCartButton = findViewById(R.id.add_to_cart_button);
        Button buyNowButton = findViewById(R.id.buy_now_button);
        ImageView cartIconImageView = findViewById(R.id.cart_icon_image_view);

        // 获取传递过来的商品信息
        String name = getIntent().getStringExtra("name");
        String description = getIntent().getStringExtra("description");
        double price = getIntent().getDoubleExtra("price", 0);

        // 设置商品详细信息
        productImageView.setImageResource(R.drawable.sample_image);
        productNameTextView.setText(name);
        productDescriptionTextView.setText(description);
        productPriceTextView.setText("￥" + price);

        // 处理加入购物车按钮点击事件
        addToCartButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Product product = new Product(name, description, price);
                ShoppingCart.getInstance().addItem(product);
            }
        });

        // 处理购买按钮点击事件
        buyNowButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // 实现购买逻辑
            }
        });

        // 处理购物车图标点击事件
        cartIconImageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(ProductDetailActivity.this, CartActivity.class);
                startActivity(intent);
            }
        });
    }
}